<template>
    <div class="dashboard-container" v-loading="loading">
        <el-button type="primary" size="small" icon="el-icon-arrow-left" @click="$router.back(-1)">返回</el-button>
        <content-card title="用户信息">
            <table class="kv-table">
                <tr>
                    <td class="kv-label">
                        用户ID
                    </td>
                    <td class="kv-content">
                        {{user.userId}}
                    </td>
                    <td class="kv-label">
                        手机号
                    </td>
                    <td class="kv-content">
                        {{user.phone}}
                    </td>
                </tr>
                <tr>
                    <td class="kv-label">
                        用户名
                    </td>
                    <td class="kv-content">
                        {{user.userName}}
                    </td>
                    <td class="kv-label">
                        注册时间
                    </td>
                    <td class="kv-content">
                        {{user.registerTime}}
                    </td>
                </tr>
            </table>
        </content-card>
        <content-card title="资产详情">
            <tableList :tableData="tableData" :userId="userId" @upload="getInfo"></tableList>
        </content-card>
    </div>
</template>

<script>
  import { getInfo } from '@/api/users'
  import tableList from './detailTableList'

  export default {
    name: "userDetail",
    components: {
      tableList
    },
    data () {
      return {
        user: {},
        userId: '',
        tableData: [],
        loading: false
      }
    },
    methods: {
      async getInfo () {
        try {
          this.loading = true
          const res = await getInfo({
            userId: this.userId
          })
          this.user = res.data.basisInfo
          this.tableData = res.data.accountList
          this.loading = false
        } catch (e) {
          console.log(e)
          this.loading = false
        }
      }
    },
    mounted () {
      if (this.$route.query.id) {
        this.userId = this.$route.query.id
        this.getInfo()
      } else {
        this.$message.warning('没有获取到userId')
        this.$router.push('/userManage')
      }
    }
  }
</script>

<style scoped>

</style>
